fix: add warning log when tool input JSON parsing fails#2064
Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: add warning log when tool input JSON parsing fails#2064Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Conversation
When a model returns malformed tool input that cannot be parsed as JSON, the SDK silently falls back to an empty dict. This adds a warning log with the tool name and the first 200 characters of the raw input to aid debugging. Fixes strands-agents#2051
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a model returns tool input that cannot be parsed as JSON, the SDK silently falls back to an empty dict. This makes it impossible to distinguish between a tool that legitimately received
{}from the model and one that received unparseable content.This change adds a
WARNINGlog before the fallback that includes the tool name and the first 200 characters of the raw input, making the silent failure observable in logs.Related Issues
Fixes #2051
Documentation PR
N/A
Type of Change
Bug fix
Testing
Added
test_handle_content_block_stop_invalid_json_logs_warningtotests/strands/event_loop/test_streaming.py. The test verifies that whenhandle_content_block_stopencounters invalid JSON tool input, it falls back to{}and emits a warning log containing "failed to parse tool input as JSON".hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.